Learn R Programming

spacesRGB (version 1.1-1)

Linear RGB and XYZ Calculation: Convert Signal RGB coordinates to XYZ, or Linear RGB

Description

Convert signal RGB coordinates to XYZ, or to linear RGB

Usage

XYZfromRGB( RGB, space='sRGB', which='scene', TF=NULL, maxSignal=1 ) 

LinearRGBfromSignalRGB( RGB, space='sRGB', which='scene', TF=NULL, maxSignal=1 )

Arguments

RGB

a numeric Nx3 matrix with non-linear signal RGB coordinates in the rows, or a vector that can be converted to such a matrix, by row. These should be in the appropriate cube [0,maxSignal]\(^3\).

space

the name of an installed RGB space. The name matching is partial and case-insensitive.

which

the output XYZ or linear RGB - either 'scene' or 'display'. Usually the OOTF for the space is the identity and so these two are the same.

TF

if not NULL, TF overrides the appropriate transfer function of space. TF can be a positive number \(\gamma\), or a transfer function that takes the interval [0,1] to itself. If TF=1, the input RGB values taken to be linear and not clamped (see Value). If TF is not NULL in LinearRGBfromSignalRGB(), then space and which are ignored.

maxSignal

maximum value of the input signal RGB. Other common values are 100, 255, 1023, 4095, and 65535. Even when 1, they are still taken to be non-linear signal values.

Value

XYZfromRGB() returns a data.frame with N rows and these columns:

XYZ

the calculated XYZ vectors. These are for viewing under the white point of the given RGB space.

OutOfGamut

a logical vector. TRUE means the input signal RGB is outside the cube [0,maxSignal]\(^3\). If TF is not 1, then the input signal RGBs are clamped to the cube before further calculations.

LinearRGBfromSignalRGB() returns a data.frame with N rows and these columns:

RGB

the calculated linear RGB vectors. These are normalized to the unit cube.

OutOfGamut

a logical vector. TRUE means the input signal RGB is outside the cube [0,maxSignal]\(^3\). If TF is not 1, then the signal RGBs are clamped to the cube before linearizing.

In case of error, both functions return NULL.

References

Wikipedia. RGB color space. https://en.wikipedia.org/wiki/RGB_color_space

See Also

RGBfromXYZ(), SignalRGBfromLinearRGB(), installRGB()

Examples

Run this code
# NOT RUN {
XYZfromRGB( c(128,200,255, 0,0,0,  255,255,255), max=255 )$XYZ * 100
##              X         Y       Z
##  [1,] 47.59995  53.11406 102.332
##  [2,]  0.00000   0.00000   0.000
##  [3,] 95.04700 100.00000 108.883


XYZfromRGB( c(128,200,255, 0,0,0,  255,255,255), space='Adobe', max=255 )$XYZ   * 100
##              X         Y        Z
##  [1,] 42.36074  50.82687 103.8475
##  [2,]  0.00000   0.00000   0.0000
##  [3,] 95.04700 100.00000 108.8830
# }

Run the code above in your browser using DataLab